﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Coding4Fun.Phone.Controls">

	<ResourceDictionary.MergedDictionaries>
		<ResourceDictionary Source="/Coding4Fun.Phone.Controls;component/Themes/Common/CommonStyles.xaml" />
	</ResourceDictionary.MergedDictionaries>
	
	<Style TargetType="local:OpacityToggleButton">
		<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
		<Setter Property="Background" Value="{StaticResource PhoneForegroundBrush}"/>
		<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
		<Setter Property="FontSize" Value="12" />

		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="local:OpacityToggleButton">
					<Grid>
						<VisualStateManager.VisualStateGroups>
							<VisualStateGroup x:Name="CheckStates">
								<VisualState x:Name="Checked" />
								<!-- set in code behind-->
								<VisualState x:Name="Unchecked" />
								<!-- set in code behind-->
								<VisualState x:Name="Indeterminate"/>
							</VisualStateGroup>
							<VisualStateGroup x:Name="CommonStates">
								<VisualState x:Name="Normal"/>

								<VisualState x:Name="Disabled">
									<Storyboard>
										<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ButtonForeground">
											<DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
										</ObjectAnimationUsingKeyFrames>
										<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="ButtonForeground">
											<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
										</ObjectAnimationUsingKeyFrames>
										<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentBody">
											<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
										</ObjectAnimationUsingKeyFrames>
									</Storyboard>
								</VisualState>
							</VisualStateGroup>
						</VisualStateManager.VisualStateGroups>
						<Rectangle Fill="Transparent" />
						<Border 
							Height="{TemplateBinding Height}"
							Width="{TemplateBinding Width}"
							Padding="{TemplateBinding Padding}" 
							BorderThickness="0" 
							BorderBrush="Transparent">
							<StackPanel 
								Orientation="{TemplateBinding Orientation}"
								VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
								HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
								<Grid 
									Width="{TemplateBinding ButtonWidth}" 
									Height="{TemplateBinding ButtonHeight}" 
									Margin="0,-10, 0, 0">
									<Rectangle
										x:Name="ButtonForeground" 
										Fill="{TemplateBinding Background}" 
										Opacity="{TemplateBinding UncheckedOpacity}"
										Margin="{StaticResource PhoneTouchTargetOverhang}">
										<Rectangle.OpacityMask>
											<ImageBrush 
												x:Name="OpacityImageBrush" 
												Stretch="{TemplateBinding Stretch}" />
										</Rectangle.OpacityMask>
									</Rectangle>
								</Grid>

								<ContentControl 
									x:Name="ContentBody" 
									Margin="0"
									Content="{TemplateBinding Content}" 
									FontSize="{TemplateBinding FontSize}"
									Style="{StaticResource AppBarText}"/>

							</StackPanel>
						</Border>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>